<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="theme-color" content="#0078E7"><meta name="author" content="CC康纳百川"><meta name="copyright" content="CC康纳百川"><meta name="generator" content="Hexo 5.2.0"><meta name="theme" content="hexo-theme-yun"><title>生产实习 | CC康纳百川</title><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@900&amp;display=swap" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/star-markdown-css@0.1.21/dist/yun/yun-markdown.min.css"><script src="//at.alicdn.com/t/font_1140697_ed8vp4atwoj.js" async></script><script src="https://cdn.jsdelivr.net/npm/scrollreveal/dist/scrollreveal.min.js" defer></script><script>document.addEventListener("DOMContentLoaded", () => {
  [".post-card",".post-content img"].forEach((target)=> {
    ScrollReveal().reveal(target);
  })
});
</script><link rel="shortcut icon" type="image/svg+xml" href="/yun/yun.svg"><link rel="mask-icon" href="/yun/yun.svg" color="#0078E7"><link rel="alternate icon" href="/yun.ico"><link rel="preload" href="/yun/css/hexo-theme-yun.css" as="style"><link rel="preload" href="/yun/js/utils.js" as="script"><link rel="preload" href="/yun/js/hexo-theme-yun.js" as="script"><link rel="prefetch" href="/yun/js/sidebar.js" as="script"><link rel="preconnect" href="https://cdn.jsdelivr.net" crossorigin><link rel="stylesheet" href="/yun/css/hexo-theme-yun.css"><script id="yun-config">
    const Yun = window.Yun || {};
    window.CONFIG = {"hostname":"ccknbc.github.io","root":"/yun/","title":"云游君的小站","version":"1.2.0","mode":"time","copycode":true,"anonymous_image":"https://cdn.jsdelivr.net/gh/YunYouJun/cdn/img/avatar/none.jpg","say":{"api":"https://v1.hitokoto.cn","hitokoto":true},"local_search":{"path":"/yun/search.xml"},"fireworks":{"colors":["102, 167, 221","62, 131, 225","33, 78, 194"]}};
  </script><script>(function(){
  var bp = document.createElement('script');
  var curProtocol = window.location.protocol.split(':')[0];
  if (curProtocol === 'https') {
    bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
  }
  else {
    bp.src = 'http://push.zhanzhang.baidu.com/push.js';
  }
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(bp, s);
})();</script><meta name="description" content="等待更新中 时间为整点定时发布  待同步 取消加密 图片还未上传至图床 视频嵌入还未做好 YouTube已OK  目录在左侧  超声波及温度传感摇摆风扇所用元件：UNO R3开发板 ×1 大面包板 ×1 舵机 ×1  舵机支架 ×1 电位器 ×1 1k电阻 ×1 USB数据线 ×1 小风扇 ×1 摇头风扇支架组件 ×1 ULN2003AN驱动芯片 ×1 三色LED ×1 鳄鱼夹 ×2 面包线 若干">
<meta property="og:type" content="article">
<meta property="og:title" content="生产实习">
<meta property="og:url" content="https://ccknbc.github.io/yun/posts/2/">
<meta property="og:site_name" content="CC康纳百川">
<meta property="og:description" content="等待更新中 时间为整点定时发布  待同步 取消加密 图片还未上传至图床 视频嵌入还未做好 YouTube已OK  目录在左侧  超声波及温度传感摇摆风扇所用元件：UNO R3开发板 ×1 大面包板 ×1 舵机 ×1  舵机支架 ×1 电位器 ×1 1k电阻 ×1 USB数据线 ×1 小风扇 ×1 摇头风扇支架组件 ×1 ULN2003AN驱动芯片 ×1 三色LED ×1 鳄鱼夹 ×2 面包线 若干">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-06-29T13:00:00.000Z">
<meta property="article:modified_time" content="2020-06-29T13:00:00.000Z">
<meta property="article:author" content="CC康纳百川">
<meta property="article:tag" content="学习">
<meta property="article:tag" content="生产实习">
<meta name="twitter:card" content="summary"><script src="/yun/js/ui/mode.js"></script></head><body><script defer src="https://cdn.jsdelivr.net/npm/animejs@latest/anime.min.js"></script><script defer src="/yun/js/ui/fireworks.js"></script><canvas class="fireworks"></canvas><div class="container"><a class="sidebar-toggle hty-icon-button" id="menu-btn"><div class="hamburger hamburger--spin" type="button"><span class="hamburger-box"><span class="hamburger-inner"></span></span></div></a><div class="sidebar-toggle sidebar-overlay"></div><aside class="sidebar"><script src="/yun/js/sidebar.js"></script><ul class="sidebar-nav"><li class="sidebar-nav-item sidebar-nav-toc hty-icon-button sidebar-nav-active" data-target="post-toc-wrap" title="文章目录"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-list-ordered"></use></svg></li><li class="sidebar-nav-item sidebar-nav-overview hty-icon-button" data-target="site-overview-wrap" title="站点概览"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-passport-line"></use></svg></li></ul><div class="sidebar-panel" id="site-overview-wrap"><div class="site-info mickey-mouse"><a class="site-author-avatar" href="/yun/about/" title="CC康纳百川"><img width="96" loading="lazy" src="/yun/Yun.png" alt="CC康纳百川"><span class="site-author-status" title="永远相信美好的事情即将发生">😊</span></a><div class="site-author-name"><a href="/yun/about/">CC康纳百川</a></div><a class="site-name" href="/yun/about/site">CC康纳百川</a><sub class="site-subtitle">Hello Word</sub><div class="site-desciption">一个无趣的人</div></div><nav class="site-state"><a class="site-state-item hty-icon-button icon-home" href="/yun/" title="首页"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-home-4-line"></use></svg></span></a><div class="site-state-item"><a href="/yun/archives/" title="归档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-archive-line"></use></svg></span><span class="site-state-item-count">10</span></a></div><div class="site-state-item"><a href="/yun/categories/" title="分类"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-folder-2-line"></use></svg></span><span class="site-state-item-count">16</span></a></div><div class="site-state-item"><a href="/yun/tags/" title="标签"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="site-state-item-count">18</span></a></div><a class="site-state-item hty-icon-button" target="_blank" rel="noopener" href="https://yun.yunyoujun.cn" title="文档"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-settings-line"></use></svg></span></a></nav><hr style="margin-bottom:0.5rem"><div class="links-of-author"><a class="links-of-author-item hty-icon-button" rel="noopener" href="/atom.xml" title="RSS" target="_blank" style="color:orange"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-rss-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://shang.qq.com/wpa/qunwpa?idkey=c929e704022704d8cced9ec355d44a3fa7ad34aea12cef1de03d75d3d7d5b059" title="QQ 群" target="_blank" style="color:#12B7F5"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-qq-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://github.com/YunYouJun" title="GitHub" target="_blank" style="color:#6e5494"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-github-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://weibo.com/jizhideyunyoujun" title="微博" target="_blank" style="color:#E6162D"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-weibo-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://www.douban.com/people/yunyoujun/" title="豆瓣" target="_blank" style="color:#007722"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-douban-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://music.163.com/#/user/home?id=247102977" title="网易云音乐" target="_blank" style="color:#C20C0C"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-netease-cloud-music-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://www.zhihu.com/people/yunyoujun/" title="知乎" target="_blank" style="color:#0084FF"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-zhihu-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://space.bilibili.com/1579790" title="哔哩哔哩" target="_blank" style="color:#FF8EB3"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-bilibili-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://twitter.com/YunYouJun" title="Twitter" target="_blank" style="color:#1da1f2"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-twitter-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://t.me/elpsycn" title="Telegram Channel" target="_blank" style="color:#0088CC"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-telegram-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="mailto:me@yunyoujun.cn" title="E-Mail" target="_blank" style="color:#8E71C1"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-mail-line"></use></svg></a><a class="links-of-author-item hty-icon-button" rel="noopener" href="https://travellings.now.sh/" title="Travelling" target="_blank" style="color:var(--hty-text-color)"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-send-plane-2-line"></use></svg></a></div><hr style="margin:0.5rem 1rem"><div class="links"><a class="links-item hty-icon-button" href="/yun/links/" title="我的小伙伴们" style="color:dodgerblue"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-genderless-line"></use></svg></a></div><br><a class="links-item hty-icon-button" id="toggle-mode-btn" href="javascript:;" title="Mode" style="color: #f1cb64"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-contrast-2-line"></use></svg></a></div><div class="sidebar-panel sidebar-panel-active" id="post-toc-wrap"><div class="post-toc"><div class="post-toc-content"><ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%B6%85%E5%A3%B0%E6%B3%A2%E5%8F%8A%E6%B8%A9%E5%BA%A6%E4%BC%A0%E6%84%9F%E6%91%87%E6%91%86%E9%A3%8E%E6%89%87"><span class="toc-number">1.</span> <span class="toc-text">超声波及温度传感摇摆风扇</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E6%89%80%E7%94%A8%E5%85%83%E4%BB%B6%EF%BC%9A"><span class="toc-number">1.1.</span> <span class="toc-text">所用元件：</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%EF%BC%9AArduino-IDE-Mind"><span class="toc-number">1.2.</span> <span class="toc-text">开发环境：Arduino IDE,Mind+</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E9%A2%84%E6%9C%9F%E8%A6%81%E6%B1%82%EF%BC%9A"><span class="toc-number">1.3.</span> <span class="toc-text">预期要求：</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%A4%A7%E8%87%B4%E8%AE%BE%E8%AE%A1%E6%80%9D%E8%B7%AF%EF%BC%9A"><span class="toc-number">1.4.</span> <span class="toc-text">大致设计思路：</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%85%B7%E4%BD%93%E5%AE%9E%E7%8E%B0%E6%BA%90%E4%BB%A3%E7%A0%81%EF%BC%9A"><span class="toc-number">1.5.</span> <span class="toc-text">具体实现源代码：</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#YouTube%EF%BC%9A"><span class="toc-number">1.6.</span> <span class="toc-text">YouTube：</span></a></li></ol></li></ol></div></div></div></aside><main class="sidebar-translate" id="content"><div id="post"><article class="post-block" itemscope itemtype="https://schema.org/Article"><link itemprop="mainEntityOfPage" href="https://ccknbc.github.io/yun/yun/posts/2/"><span hidden itemprop="author" itemscope itemtype="https://schema.org/Person"><meta itemprop="name" content="CC康纳百川"><meta itemprop="description"></span><span hidden itemprop="publisher" itemscope itemtype="https://schema.org/Organization"><meta itemprop="name" content="CC康纳百川"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">生产实习<a class="post-edit-link" href="https://github.com/ccknbc-actions/blog-yun/blob/master/source/_posts/学习/生产实习.md" target="_blank" title="编辑" rel="noopener"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-edit-line"></use></svg></a></h1><div class="post-meta"><div class="post-time" style="display:block"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-calendar-line"></use></svg></span> <span class="post-meta-icon-text">发表于</span> <time title="创建时间：2020-06-29 21:00:00" itemprop="dateCreated datePublished" datetime="2020-06-29T21:00:00+08:00">2020-06-29</time></div><span class="post-count"><span class="post-symbolcount"><span class="post-meta-item-icon" title="本文字数"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-file-word-line"></use></svg></span> <span title="本文字数">1.2k</span><span class="post-meta-divider">-</span><span class="post-meta-item-icon" title="阅读时长"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-timer-line"></use></svg></span> <span title="阅读时长">5m</span></span></span><span class="post-busuanzi"><span class="post-meta-divider">-</span><span class="post-meta-item-icon" title="阅读次数"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-eye-line"></use></svg> <span id="busuanzi_value_page_pv"></span></span></span><div class="post-classify"><span class="post-category"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-folder-line"></use></svg></span> <span itemprop="about" itemscope itemtype="https://schema.org/Thing"><a class="category" href="/yun/categories/%E5%AD%A6%E4%B9%A0/" style="--text-color:var(--hty-text-color)" itemprop="url" rel="index"><span itemprop="text">学习</span></a></span> > <span itemprop="about" itemscope itemtype="https://schema.org/Thing"><a class="category" href="/yun/categories/%E5%AD%A6%E4%B9%A0/%E7%94%9F%E4%BA%A7%E5%AE%9E%E4%B9%A0/" style="--text-color:var(--hty-text-color)" itemprop="url" rel="index"><span itemprop="text">生产实习</span></a></span></span><span class="post-tag"><span class="post-meta-divider">-</span><a class="tag" href="/yun/tags/%E5%AD%A6%E4%B9%A0/" style="--text-color:var(--hty-text-color)"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="tag-name">学习</span></a><a class="tag" href="/yun/tags/%E7%94%9F%E4%BA%A7%E5%AE%9E%E4%B9%A0/" style="--text-color:var(--hty-text-color)"><span class="post-meta-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-price-tag-3-line"></use></svg></span><span class="tag-name">生产实习</span></a></span></div><div class="post-author"><div class="author-avatar"><img src="https://www.gravatar.com/avatar/1928aaddbe6e7107395bf3ac99f35886?s=20&amp;d=https%3A%2F%2Fcdn.jsdelivr.net%2Fgh%2FYunYouJun%2Fcdn%2Fimg%2Favatar%2Fnone.jpg"></div><span class="author-name">CC</span></div></div></header><section class="post-body" itemprop="articleBody"><div class="post-content markdown-body" style="--smc-primary:#0078E7;"><p><strong>等待更新中 时间为整点定时发布</strong></p>
<blockquote>
<p><strong>待同步</strong> <strong>取消加密</strong></p>
<p><strong>图片还未上传至图床</strong></p>
<p><strong>视频嵌入还未做好 YouTube已OK</strong> </p>
<p><strong>目录在左侧</strong></p>
</blockquote>
<h5 id="超声波及温度传感摇摆风扇"><a href="#超声波及温度传感摇摆风扇" class="headerlink" title="超声波及温度传感摇摆风扇"></a><strong>超声波及温度传感摇摆风扇</strong></h5><h6 id="所用元件："><a href="#所用元件：" class="headerlink" title="所用元件："></a><strong>所用元件：</strong></h6><p>UNO R3开发板 ×1</p>
<p>大面包板 ×1</p>
<p>舵机 ×1 </p>
<p>舵机支架 ×1</p>
<p>电位器 ×1</p>
<p>1k电阻 ×1</p>
<p>USB数据线 ×1</p>
<p>小风扇 ×1</p>
<p>摇头风扇支架组件 ×1</p>
<p>ULN2003AN驱动芯片 ×1</p>
<p>三色LED ×1</p>
<p>鳄鱼夹 ×2</p>
<p>面包线 若干</p>
<h6 id="开发环境：Arduino-IDE-Mind"><a href="#开发环境：Arduino-IDE-Mind" class="headerlink" title="开发环境：Arduino IDE,Mind+"></a><strong>开发环境：</strong>Arduino IDE,Mind+</h6><h6 id="预期要求："><a href="#预期要求：" class="headerlink" title="预期要求："></a><strong>预期要求：</strong></h6><p>通过超声波测距和温度传感控制舵机是否旋转，当距离小于30cm或温度大于30℃时在设定的角度之间来回旋转；通过电位器控制电机，小风扇旋转的快慢。</p>
<h6 id="大致设计思路："><a href="#大致设计思路：" class="headerlink" title="大致设计思路："></a><strong>大致设计思路：</strong></h6><h6 id="具体实现源代码："><a href="#具体实现源代码：" class="headerlink" title="具体实现源代码："></a><strong>具体实现源代码：</strong></h6><figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="comment">//引入库文件</span></span><br><span class="line">\<span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;Servo.h&gt;//舵机库，之间要有空格，否则编译时会报错。</span></span></span><br><span class="line">\<span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;Wire.h&gt; //是I2C通讯的，Arduino和I2C设备通讯使用的(SCLK DIN RCLK) </span></span></span><br><span class="line"><span class="comment">//以下为函数声明</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">zhuan</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">buzhuan</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">chaoshengbo</span><span class="params">()</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">wendu</span><span class="params">()</span></span>;</span><br><span class="line"><span class="comment">//以下为变量声明及初始声明</span></span><br><span class="line">Servo myservo;<span class="comment">//定义舵机变量名</span></span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">char</span> jiao;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> P=A0;<span class="comment">//电位器输入引脚</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> U=<span class="number">8</span>;</span><br><span class="line"><span class="keyword">int</span> sensorValue=<span class="number">0</span>;<span class="comment">//电位器电压值</span></span><br><span class="line"><span class="keyword">int</span> outputValue=<span class="number">0</span>;</span><br><span class="line"><span class="comment">// 设定SR04连接的Arduino引脚</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> TrigPin = <span class="number">10</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> EchoPin = <span class="number">11</span>;</span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">long</span> distance;</span><br><span class="line"><span class="keyword">int</span> temp;<span class="comment">//温度</span></span><br><span class="line"><span class="keyword">int</span> tol;<span class="comment">//校对码</span></span><br><span class="line"><span class="keyword">int</span> j;</span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">int</span> loopCnt;</span><br><span class="line"><span class="keyword">int</span> chr[<span class="number">40</span>] = &#123;<span class="number">0</span>&#125;;<span class="comment">//创建数字数组，用来存放40个bit</span></span><br><span class="line"><span class="keyword">unsigned</span> <span class="keyword">long</span> time;</span><br><span class="line">\<span class="meta">#<span class="meta-keyword">define</span> pin 2</span></span><br><span class="line"><span class="comment">//以下为主函数部分</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">setup</span><span class="params">()</span> <span class="comment">//初始设定</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"> myservo.attach(<span class="number">9</span>);<span class="comment">//定义舵机接口</span></span><br><span class="line"> Serial.begin(<span class="number">9600</span>);<span class="comment">//设定波特率为9600 </span></span><br><span class="line"> pinMode(TrigPin, OUTPUT);<span class="comment">// 要检测引脚上输入的脉冲宽度，需要先设置为输入状态</span></span><br><span class="line"> pinMode(EchoPin, INPUT);</span><br><span class="line"> Serial.println(<span class="string">&quot;Ultrasonic sensor:&quot;</span>);</span><br><span class="line"> buzhuan();</span><br><span class="line"> chaoshengbo();</span><br><span class="line"> wendu();</span><br><span class="line"> &#125; </span><br><span class="line"><span class="comment">//以下为循环执行部分</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">loop</span><span class="params">()</span> </span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"> chaoshengbo();</span><br><span class="line"> wendu();</span><br><span class="line"> delay(<span class="number">500</span>);</span><br><span class="line"> <span class="keyword">if</span> ((distance&lt;<span class="number">30</span>) || (temp&gt;<span class="number">30</span>)) </span><br><span class="line"> &#123;</span><br><span class="line">  digitalWrite(<span class="number">4</span>, LOW);<span class="comment">//红灯灭，代表舵机未旋转</span></span><br><span class="line">  digitalWrite(<span class="number">7</span>, HIGH);<span class="comment">//绿灯亮，代表舵机开始旋转</span></span><br><span class="line">  zhuan();</span><br><span class="line">  chaoshengbo();</span><br><span class="line">  wendu();</span><br><span class="line">  delay(<span class="number">500</span>);</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>((distance&gt;<span class="number">30</span>) || (temp&lt;<span class="number">30</span>))</span><br><span class="line">  &#123;</span><br><span class="line">  buzhuan();</span><br><span class="line">  chaoshengbo();</span><br><span class="line">  wendu();</span><br><span class="line">  delay(<span class="number">500</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//以下为函数定义部分</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">zhuan</span><span class="params">()</span><span class="comment">//定义舵机转</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"> myservo.write(jiao);</span><br><span class="line"> sensorValue=analogRead(P);</span><br><span class="line"> outputValue=<span class="built_in">map</span>(sensorValue,<span class="number">0</span>,<span class="number">1023</span>,<span class="number">0</span>,<span class="number">255</span>);</span><br><span class="line"> analogWrite(U,outputValue);</span><br><span class="line"> <span class="keyword">for</span>(jiao=<span class="number">30</span>;jiao&lt;<span class="number">150</span>;jiao++)</span><br><span class="line">  &#123;</span><br><span class="line">   myservo.write(jiao);<span class="comment">//设置舵机旋转的角度 </span></span><br><span class="line">   delay(<span class="number">10</span>);  </span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">for</span>(jiao=<span class="number">150</span>;jiao&gt;<span class="number">30</span>;jiao--)</span><br><span class="line">  &#123;</span><br><span class="line">   myservo.write(jiao);<span class="comment">//设置舵机旋转的角度 </span></span><br><span class="line">   delay(<span class="number">10</span>);  </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">buzhuan</span><span class="params">()</span><span class="comment">//定义舵机不转</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"> digitalWrite(TrigPin, LOW);</span><br><span class="line"> delayMicroseconds(<span class="number">2</span>);</span><br><span class="line"> myservo.write(jiao);</span><br><span class="line"> digitalWrite(<span class="number">4</span>, HIGH);</span><br><span class="line"> digitalWrite(<span class="number">7</span>, LOW);</span><br><span class="line"> sensorValue=analogRead(P);</span><br><span class="line"> outputValue=<span class="built_in">map</span>(sensorValue,<span class="number">0</span>,<span class="number">1023</span>,<span class="number">0</span>,<span class="number">255</span>);</span><br><span class="line"> analogWrite(U,outputValue);</span><br><span class="line"> myservo.write(jiao); </span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">chaoshengbo</span><span class="params">()</span><span class="comment">//定义超声波测距</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"> <span class="comment">// 产生一个10us的高脉冲去触发TrigPin</span></span><br><span class="line"> digitalWrite(TrigPin, LOW);</span><br><span class="line"> delayMicroseconds(<span class="number">2</span>);</span><br><span class="line"> digitalWrite(TrigPin, HIGH);</span><br><span class="line"> delayMicroseconds(<span class="number">10</span>);</span><br><span class="line"> digitalWrite(TrigPin, LOW); <span class="comment">// 检测脉冲宽度，并计算出距离</span></span><br><span class="line"> <span class="comment">//delayMicroseconds(2);</span></span><br><span class="line"> distance = pulseIn(EchoPin, HIGH) / <span class="number">58.00</span>;</span><br><span class="line"> Serial.print(<span class="string">&quot;距离：&quot;</span>);</span><br><span class="line"> Serial.print(distance);</span><br><span class="line"> Serial.print(<span class="string">&quot;cm&quot;</span>);</span><br><span class="line"> Serial.println();</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">wendu</span><span class="params">()</span><span class="comment">//定义温度测量</span></span></span><br><span class="line"><span class="function"></span>&#123;</span><br><span class="line"> bgn:</span><br><span class="line"> delay(<span class="number">500</span>);</span><br><span class="line"><span class="comment">//设置2号接口模式为：输出</span></span><br><span class="line"><span class="comment">//输出低电平20ms（&gt;18ms）</span></span><br><span class="line"><span class="comment">//输出高电平40μs</span></span><br><span class="line"> pinMode(pin,OUTPUT);</span><br><span class="line"> digitalWrite(pin,LOW);</span><br><span class="line"> delay(<span class="number">20</span>);</span><br><span class="line"> digitalWrite(pin,HIGH);</span><br><span class="line"> delayMicroseconds(<span class="number">40</span>);</span><br><span class="line"> digitalWrite(pin,LOW);</span><br><span class="line"><span class="comment">//设置2号接口模式：输入</span></span><br><span class="line"> pinMode(pin,INPUT);</span><br><span class="line"> <span class="comment">//高电平响应信号 </span></span><br><span class="line"> loopCnt=<span class="number">10000</span>;</span><br><span class="line"> <span class="keyword">while</span>(digitalRead(pin) != HIGH)</span><br><span class="line"> &#123;</span><br><span class="line">  <span class="keyword">if</span>(loopCnt-- == <span class="number">0</span>)</span><br><span class="line">  &#123;</span><br><span class="line"><span class="comment">//如果长时间不返回高电平，输出个提示，重头开始。</span></span><br><span class="line">   Serial.println(<span class="string">&quot;HIGH&quot;</span>);</span><br><span class="line">   <span class="keyword">goto</span> bgn;</span><br><span class="line">  &#125;</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="comment">//低电平响应信号</span></span><br><span class="line"> loopCnt=<span class="number">30000</span>;</span><br><span class="line"> <span class="keyword">while</span>(digitalRead(pin) != LOW)</span><br><span class="line"> &#123;</span><br><span class="line">  <span class="keyword">if</span>(loopCnt-- == <span class="number">0</span>)</span><br><span class="line">  &#123;</span><br><span class="line"><span class="comment">//如果长时间不返回低电平，输出个提示，重头开始。</span></span><br><span class="line">   Serial.println(<span class="string">&quot;LOW&quot;</span>);</span><br><span class="line">   <span class="keyword">goto</span> bgn;</span><br><span class="line">  &#125;</span><br><span class="line"> &#125;</span><br><span class="line"><span class="comment">//开始读取bit1-40的数值  </span></span><br><span class="line">  <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">40</span>;i++)</span><br><span class="line"> &#123;</span><br><span class="line">  <span class="keyword">while</span>(digitalRead(pin) == LOW)</span><br><span class="line">  &#123;&#125;</span><br><span class="line"><span class="comment">//当出现高电平时，记下时间“time”</span></span><br><span class="line">  time = micros();</span><br><span class="line">  <span class="keyword">while</span>(digitalRead(pin) == HIGH)</span><br><span class="line">  &#123;&#125;</span><br><span class="line"><span class="comment">//当出现低电平，记下时间，再减去刚才储存的time</span></span><br><span class="line"><span class="comment">//得出的值若大于50μs，则为‘1’，否则为‘0’</span></span><br><span class="line"><span class="comment">//并储存到数组里去</span></span><br><span class="line">  <span class="keyword">if</span> (micros() - time &gt;<span class="number">50</span>)</span><br><span class="line">  &#123;</span><br><span class="line">   chr[i]=<span class="number">1</span>;</span><br><span class="line">  &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">   chr[i]=<span class="number">0</span>;</span><br><span class="line">  &#125;</span><br><span class="line"> &#125;  </span><br><span class="line"><span class="comment">//温度，8位的bit，转换为数值</span></span><br><span class="line">temp=chr[<span class="number">16</span>]*<span class="number">128</span>+chr[<span class="number">17</span>]*<span class="number">64</span>+chr[<span class="number">18</span>]*<span class="number">32</span>+chr[<span class="number">19</span>]*<span class="number">16</span>+chr[<span class="number">20</span>]*<span class="number">8</span>+chr[<span class="number">21</span>]*<span class="number">4</span>+chr[<span class="number">22</span>]*<span class="number">2</span>+chr[<span class="number">23</span>];</span><br><span class="line"> <span class="comment">//校对码，8位的bit，转换为数值</span></span><br><span class="line">tol=chr[<span class="number">32</span>]*<span class="number">128</span>+chr[<span class="number">33</span>]*<span class="number">64</span>+chr[<span class="number">34</span>]*<span class="number">32</span>+chr[<span class="number">35</span>]*<span class="number">16</span>+chr[<span class="number">36</span>]*<span class="number">8</span>+chr[<span class="number">37</span>]*<span class="number">4</span>+chr[<span class="number">38</span>]*<span class="number">2</span>+chr[<span class="number">39</span>];</span><br><span class="line"><span class="comment">//输出：温度、湿度、校对码</span></span><br><span class="line">  Serial.print(<span class="string">&quot;温度：&quot;</span>);</span><br><span class="line">  Serial.print(temp);</span><br><span class="line">  Serial.println(<span class="string">&quot;℃&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>串口串口显示情况1，此时温度为28℃，距离为275cm左右，都不满足舵机旋转的条件，红色指示灯常亮。</p>
<p>对应的实际运行情况如下图所示：</p>
<p>串口串口显示情况2，串口串口显示情况1，此时温度为28℃，距离为5cm左右，满足舵机旋转的条件，绿色指示灯常亮。</p>
<p>对应的实际运行情况如下图所示</p>
<h6 id="YouTube："><a href="#YouTube：" class="headerlink" title="YouTube："></a><strong>YouTube：</strong></h6><iframe width="900" height="506" src="https://www.youtube.com/embed/hSkkb7gR_kU" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div><ul class="post-copyright"><li class="post-copyright-author"><strong>本文作者：</strong>CC</li><li class="post-copyright-link"><strong>本文链接：</strong><a href="https://ccknbc.github.io/yun/posts/2/" title="生产实习">https://ccknbc.github.io/yun/posts/2/</a></li><li class="post-copyright-license"><strong>版权声明：</strong>本博客所有文章除特别声明外，均默认采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" target="_blank" rel="noopener" title="CC BY-NC-SA 4.0 "><svg class="icon"><use xlink:href="#icon-creative-commons-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-by-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-nc-line"></use></svg><svg class="icon"><use xlink:href="#icon-creative-commons-sa-line"></use></svg></a> 许可协议。</li></ul><script>document.addEventListener('copy', function (event) {
  const clipboardData = event.clipboardData || window.clipboardData;
  if (!clipboardData) { return; }
  const text = window.getSelection().toString();
  if (text) {
    event.preventDefault();
    clipboardData.setData('text/plain', text + '\n\n本文作者：CC\n本文链接：https://ccknbc.github.io/yun/posts/2/\n版权声明：本博客所有文章除特别声明外，均默认采用 CC BY-NC-SA 4.0 许可协议。');
  }
});</script></section></article><div class="post-nav"><div class="post-nav-item"><a class="post-nav-prev" href="/yun/posts/3/" rel="prev" title="HEXO折腾"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-left-s-line"></use></svg><span class="post-nav-text">HEXO折腾</span></a></div><div class="post-nav-item"><a class="post-nav-next" href="/yun/posts/1/" rel="next" title="基于小波变换的数字水印检测"><span class="post-nav-text">基于小波变换的数字水印检测</span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-right-s-line"></use></svg></a></div></div></div><div id="comment"><div class="comment-tooltip text-center"><span>点击按钮跳转 GitHub Issues 评论</span><br><span>若没有本文 Issue，您可以使用 Comment 模版新建</span><br><a class="hty-button hty-button--raised" id="github-issues" target="_blank" rel="noopener" href="https://github.com/ccknbc-backup/comments/issues?q=is:issue+生产实习">GitHub Issues</a></div><div id="disqus_thread"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/disqusjs@latest/dist/disqusjs.css"><script src="https://cdn.jsdelivr.net/npm/disqusjs@latest/dist/disqus.js"></script><script>const disqusjsConfig = {"enable":true,"shortname":"ccknbc","count":true,"apikey":"Z6F8Gc9KvW2YCh6p11VRVNvMBYfdaKR3IMRFLVmoYaIQJ2ysp38fZ9tivPdgyBWu","siteName":"CC的部落格","identifier":null,"url":null,"title":null,"nesting":4,"nocomment":"这里冷冷清清的，一条评论也没有，快来留下脚印吧！","admin":"ccknbc","adminLabel":"ccknbc"}
function loadDisqus() {
  const dsqjs = new DisqusJS(disqusjsConfig)
}</script><script src="/yun/js/comments/disqus.js"></script><style>.utterances {
  max-width: 100%;
}</style><script src="https://utteranc.es/client.js" repo="ccknbc-backup/comments" issue-term="title" label="💬comment" theme="github-light" crossorigin="anonymous" async></script></div></main><footer class="sidebar-translate" id="footer"><div class="copyright"><span>&copy; 2020 </span><span class="with-love" id="animate"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-cloud-line"></use></svg></span><span class="author"> CC康纳百川</span></div><div class="powered"><span>由 <a href="https://hexo.io" target="_blank" rel="noopener">Hexo</a> 驱动 v5.2.0</span><span class="footer-separator">|</span><span>主题 - <a rel="noopener" href="https://github.com/YunYouJun/hexo-theme-yun" target="_blank"><span>Yun</span></a> v1.2.0</span></div><div class="live_time"><span>本博客已萌萌哒地运行</span><span id="display_live_time"></span><span class="moe-text">(●'◡'●)</span><script>function blog_live_time() {
  window.setTimeout(blog_live_time, 1000);
  const start = new Date('2020-06-04T00:00:00');
  const now = new Date();
  const timeDiff = (now.getTime() - start.getTime());
  const msPerMinute = 60 * 1000;
  const msPerHour = 60 * msPerMinute;
  const msPerDay = 24 * msPerHour;
  const passDay = Math.floor(timeDiff / msPerDay);
  const passHour = Math.floor((timeDiff % msPerDay) / 60 / 60 / 1000);
  const passMinute = Math.floor((timeDiff % msPerHour) / 60 / 1000);
  const passSecond = Math.floor((timeDiff % msPerMinute) / 1000);
  display_live_time.innerHTML = " " + passDay + " 天 " + passHour + " 小时 " + passMinute + " 分 " + passSecond + " 秒";
}
blog_live_time();
</script></div><div id="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_site_uv" title="总访客量"><span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-user-line"></use></svg></span><span id="busuanzi_value_site_uv"></span></span><span class="footer-separator">|</span><span id="busuanzi_container_site_pv" title="总访问量"><span><svg class="icon" aria-hidden="true"><use xlink:href="#icon-eye-line"></use></svg></span><span id="busuanzi_value_site_pv"></span></span></div></footer><a class="hty-icon-button" id="goUp" aria-label="back-to-top" href="#"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-arrow-up-s-line"></use></svg><svg class="progress-circle-container" viewBox="0 0 100 100"><circle class="progress-circle" id="progressCircle" cx="50" cy="50" r="48" fill="none" stroke="#0078E7" stroke-width="2" stroke-linecap="round"></circle></svg></a><a class="popup-trigger hty-icon-button icon-search" id="search" href="javascript:;" title="搜索"><span class="site-state-item-icon"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-search-line"></use></svg></span></a><script>window.addEventListener("DOMContentLoaded", () => {
  // Handle and trigger popup window
  document.querySelector(".popup-trigger").addEventListener("click", () => {
    document.querySelector(".popup").classList.add("show");
    setTimeout(() => {
      document.querySelector(".search-input").focus();
    }, 100);
  });

  // Monitor main search box
  const onPopupClose = () => {
    document.querySelector(".popup").classList.remove("show");
  };

  document.querySelector(".popup-btn-close").addEventListener("click", () => {
    onPopupClose();
  });

  window.addEventListener("keyup", event => {
    if (event.key === "Escape") {
      onPopupClose();
    }
  });
});
</script><script src="/yun/js/search/local-search.js" defer></script><div class="popup search-popup"><div class="search-header"><span class="popup-btn-close close-icon hty-icon-button"><svg class="icon" aria-hidden="true"><use xlink:href="#icon-close-line"></use></svg></span></div><div class="search-input-container"><input class="search-input" id="local-search-input" type="text" placeholder="搜索..." value=""></div><div id="local-search-result"></div></div><script>const date = new Date();
const today = (date.getMonth() + 1) + "-" + date.getDate()
const mourn_days = ["4-4","9-18"]
if (mourn_days.includes(today)) {
  document.documentElement.style.filter = "grayscale(1)";
}</script></div><script defer src="/yun/js/utils.js"></script><script defer src="/yun/js/hexo-theme-yun.js"></script></body></html>